<template>
  <view id="shopAllClass">
       <category 
       :categoryList="categoryList" 
       :defaultActive='defaultActive'
       :subDefaultActive="subDefaultActive"
       :subCategoryList="subCategoryList"
       :isEdit='isEdit'
        @categoryMainClick="categoryMainClick" 
        @categorySubClick="categorySubClick"
        :height='height'
        label='class_name'
			  subLabel='serve_name'
        imgSrc='class_img_url'
        >
        </category>


        <view class="bottoms" @click="goNext" v-if="isEdit">
           确定
        </view>
  </view>
</template>

<script>
import category from "@/components/qiyue-category/qiyue-category.vue";
export default {
  components: {
    category,
  },
  data() {
    return {
      categoryList: [],
      subCategoryList: [],
      oid:null,
      uid:null,
      qu_id:null,
      od_id:null,
      serve_id:"",//服务ID
      psid:"d",//规格ID
      defaultActive:0,
      subDefaultActive:0,
      // categoryObj:{},
      optionsObj:{},
      parms:'',
      isEdit:false
    };
  },
  onLoad(options){
      uni.getSystemInfo({
		    success: res => {
				this.height = res.screenHeight - 50 - 30;
			}
    })
    if(options.oid&&options.oid!='null'){
        this.oid = options.oid
        this.uid = options.uid
        this.qu_id = options.qu_id
        this.od_id = options.od_id
        uni.setNavigationBarTitle({
					title:'编辑订单(1/3)'
        })
        if(options.od_id){
          this.isEdit =true
          this.parms = options.parms
          this.serve_id = options.pid
          this.optionsObj = options
          // console.log(this.psid,this.serve_id,JSON.parse(options.parms),'oo')
          // this.psid = JSON.parse(options.parms).service_list.filter(item=>{
          
          //   return item.pid == options.pid;
          // })[0]['psid']
          this.psid = JSON.parse(options.parms).service_list2.psid;
         console.log(this.psid,'oo',JSON.parse(options.parms))
        }
        
    }
    
  },
  methods: {
    categoryMainClick(category) {
       this.subCategoryList = category.serve_list;
    },
    categorySubClick(category) {
      //console.log(category);
      // this.categoryObj = category
      if(!this.isEdit){
        uni.navigateTo({
            url:`/pages/order/createOrder/create2?service_id=${category.id}&oid=${this.oid}&od_id=${this.od_id}&qu_id=${this.qu_id}&uid=${this.uid}`
        })
      }else{
        this.serve_id = category.id
      }
    },
    goNext(){
      // let category = this.categoryObj
      //判断服务id是否改变改变了 重置规格ID 
      console.log(this.optionsObj.pid,this.serve_id)
      if(this.optionsObj.pid==this.serve_id){//没改变原来的服务ID
         uni.navigateTo({
            url:`/pages/order/createOrder/create2?service_id=${this.serve_id}&psid=${this.psid}&isChangeServer=0&oid=${this.oid}&od_id=${this.od_id}&qu_id=${this.qu_id}&uid=${this.uid}&parms=${this.parms}`
        })
      }else{
         uni.navigateTo({
            url:`/pages/order/createOrder/create2?service_id=${this.serve_id}&isChangeServer=1&oid=${this.oid}&od_id=${this.od_id}&qu_id=${this.qu_id}&uid=${this.uid}&parms=${this.parms}`
        })
      }
     
    },
    getAllServe(parm={pid:0}){
      this.$store.dispatch("getAllServe",{pid:parm.pid}).then(res=>{
        //console.log(res,'分类')
        
        if(res.code==1){
          this.categoryList = res.data
          if(this.isEdit){
            this.categoryList.map((item,i)=>{
              item.serve_list.map((item2,i2)=>{
                if(item2.id==this.serve_id){
                  this.defaultActive =i;
                  this.subDefaultActive = i2
                }
              })
            })
          }
          this.subCategoryList = this.categoryList[this.defaultActive].serve_list
        }
      })
    },
    
  },
  mounted() {
    this.getAllServe()
    // for (var i = 0; i < 10; i++) {
    //   var subList = [];
    //   for (var j = 0; j < 15; j++) {
    //     subList.push({
    //       name: "分类" + i + ":商品" + j,
    //       logo: "http://placehold.it/50x50",
    //     });
    //   }
    //   this.categoryList.push({ name: "分类" + i, subCategoryList: subList });
    // }
    // this.subCategoryList = this.categoryList[0].subCategoryList;
  },
};
</script>

<style lang="scss" scoped>
#shopAllClass{
  .bottoms{
    position: fixed;
    bottom: 0;
    right: 0;
    width: 100%;
    background: rgb(0, 119, 255);;
    line-height: 70rpx;
    color: #fff;
    text-align: center;
  }
}
</style>